using System;
using System.Drawing;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LiteLib;
using Renci.SshNet;
using Renci.SshNet.Sftp;
using System.Collections.Generic;

namespace XpressTelephoneListener
{
	/// <summary>
	/// Summary description for SettingsForm.
	/// </summary>
	public class SettingsForm : System.Windows.Forms.Form
	{
		public int SelectedIndex = -1;
		private System.Windows.Forms.TabControl tabControlSettings;
		private System.Windows.Forms.Button buttonSettingsOK;
        private System.Windows.Forms.Button buttonSettingsCancel;
        private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Button buttonDownloadFolderBrowse;
        private System.Windows.Forms.TextBox textBoxDownloadFolder;
        private System.Windows.Forms.TabPage tabPageOutput;
		private System.Windows.Forms.NumericUpDown numericUpDownRequests;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.ColumnHeader columnHeaderMatchText;
		private System.Windows.Forms.ColumnHeader columnHeaderMatchName;
		private System.Windows.Forms.ColumnHeader columnHeader2;
        private System.Windows.Forms.CheckBox checkBox1;
        private TabPage tabPage1;
        private Button button2;
        private Button button1;
        private Label label4;
        private TextBox txtUsername;
        private Label label3;
        private TextBox txtPath;
        private Label label2;
        private MaskedTextBox txtPassword;
        private TextBox txtHost;
        private Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SettingsForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForm));
            this.tabControlSettings = new System.Windows.Forms.TabControl();
            this.tabPageOutput = new System.Windows.Forms.TabPage();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.buttonDownloadFolderBrowse = new System.Windows.Forms.Button();
            this.label10 = new System.Windows.Forms.Label();
            this.textBoxDownloadFolder = new System.Windows.Forms.TextBox();
            this.numericUpDownRequests = new System.Windows.Forms.NumericUpDown();
            this.label20 = new System.Windows.Forms.Label();
            this.label21 = new System.Windows.Forms.Label();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.txtUsername = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtPath = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtPassword = new System.Windows.Forms.MaskedTextBox();
            this.txtHost = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.buttonSettingsOK = new System.Windows.Forms.Button();
            this.buttonSettingsCancel = new System.Windows.Forms.Button();
            this.columnHeaderMatchText = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeaderMatchName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.tabControlSettings.SuspendLayout();
            this.tabPageOutput.SuspendLayout();
            this.groupBox3.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRequests)).BeginInit();
            this.tabPage1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tabControlSettings
            // 
            this.tabControlSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.tabControlSettings.Controls.Add(this.tabPageOutput);
            this.tabControlSettings.Controls.Add(this.tabPage1);
            this.tabControlSettings.Location = new System.Drawing.Point(0, 0);
            this.tabControlSettings.Name = "tabControlSettings";
            this.tabControlSettings.SelectedIndex = 0;
            this.tabControlSettings.Size = new System.Drawing.Size(466, 274);
            this.tabControlSettings.TabIndex = 1;
            this.tabControlSettings.Tag = "Settings tab";
            // 
            // tabPageOutput
            // 
            this.tabPageOutput.Controls.Add(this.groupBox3);
            this.tabPageOutput.Location = new System.Drawing.Point(4, 22);
            this.tabPageOutput.Name = "tabPageOutput";
            this.tabPageOutput.Size = new System.Drawing.Size(458, 248);
            this.tabPageOutput.TabIndex = 2;
            this.tabPageOutput.Text = "Output";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.buttonDownloadFolderBrowse);
            this.groupBox3.Controls.Add(this.label10);
            this.groupBox3.Controls.Add(this.textBoxDownloadFolder);
            this.groupBox3.Controls.Add(this.numericUpDownRequests);
            this.groupBox3.Controls.Add(this.label20);
            this.groupBox3.Controls.Add(this.label21);
            this.groupBox3.Location = new System.Drawing.Point(16, 8);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(360, 224);
            this.groupBox3.TabIndex = 7;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Target";
            // 
            // buttonDownloadFolderBrowse
            // 
            this.buttonDownloadFolderBrowse.Location = new System.Drawing.Point(304, 32);
            this.buttonDownloadFolderBrowse.Name = "buttonDownloadFolderBrowse";
            this.buttonDownloadFolderBrowse.Size = new System.Drawing.Size(24, 20);
            this.buttonDownloadFolderBrowse.TabIndex = 5;
            this.buttonDownloadFolderBrowse.Text = "...";
            this.buttonDownloadFolderBrowse.Click += new System.EventHandler(this.buttonDownloadFolderBrowse_Click);
            // 
            // label10
            // 
            this.label10.Location = new System.Drawing.Point(16, 32);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(96, 16);
            this.label10.TabIndex = 4;
            this.label10.Text = "Download folder:";
            // 
            // textBoxDownloadFolder
            // 
            this.textBoxDownloadFolder.BackColor = System.Drawing.Color.WhiteSmoke;
            this.textBoxDownloadFolder.Location = new System.Drawing.Point(136, 32);
            this.textBoxDownloadFolder.Name = "textBoxDownloadFolder";
            this.textBoxDownloadFolder.Size = new System.Drawing.Size(160, 20);
            this.textBoxDownloadFolder.TabIndex = 4;
            this.textBoxDownloadFolder.Tag = "Download folder";
            // 
            // numericUpDownRequests
            // 
            this.numericUpDownRequests.BackColor = System.Drawing.Color.WhiteSmoke;
            this.numericUpDownRequests.Location = new System.Drawing.Point(136, 64);
            this.numericUpDownRequests.Maximum = new decimal(new int[] {
            1000,
            0,
            0,
            0});
            this.numericUpDownRequests.Name = "numericUpDownRequests";
            this.numericUpDownRequests.Size = new System.Drawing.Size(64, 20);
            this.numericUpDownRequests.TabIndex = 10;
            this.numericUpDownRequests.Tag = "View last requests count";
            this.numericUpDownRequests.Value = new decimal(new int[] {
            20,
            0,
            0,
            0});
            // 
            // label20
            // 
            this.label20.Location = new System.Drawing.Point(32, 64);
            this.label20.Name = "label20";
            this.label20.Size = new System.Drawing.Size(64, 16);
            this.label20.TabIndex = 12;
            this.label20.Text = "View last";
            // 
            // label21
            // 
            this.label21.Location = new System.Drawing.Point(208, 64);
            this.label21.Name = "label21";
            this.label21.Size = new System.Drawing.Size(64, 16);
            this.label21.TabIndex = 11;
            this.label21.Tag = "";
            this.label21.Text = "(Requests)";
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.button2);
            this.tabPage1.Controls.Add(this.button1);
            this.tabPage1.Controls.Add(this.label4);
            this.tabPage1.Controls.Add(this.txtUsername);
            this.tabPage1.Controls.Add(this.label3);
            this.tabPage1.Controls.Add(this.txtPath);
            this.tabPage1.Controls.Add(this.label2);
            this.tabPage1.Controls.Add(this.txtPassword);
            this.tabPage1.Controls.Add(this.txtHost);
            this.tabPage1.Controls.Add(this.label1);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(458, 248);
            this.tabPage1.TabIndex = 3;
            this.tabPage1.Text = "tabPage1";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // button2
            // 
            this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.button2.Location = new System.Drawing.Point(107, 177);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(117, 23);
            this.button2.TabIndex = 14;
            this.button2.Text = "Test Connection";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button1
            // 
            this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.button1.Location = new System.Drawing.Point(239, 177);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(117, 23);
            this.button1.TabIndex = 15;
            this.button1.Text = "Save Configuration";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click_1);
            // 
            // label4
            // 
            this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(89, 131);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(59, 13);
            this.label4.TabIndex = 17;
            this.label4.Text = "Password :";
            // 
            // txtUsername
            // 
            this.txtUsername.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtUsername.Location = new System.Drawing.Point(164, 102);
            this.txtUsername.Name = "txtUsername";
            this.txtUsername.Size = new System.Drawing.Size(100, 20);
            this.txtUsername.TabIndex = 11;
            this.txtUsername.Tag = "UserName";
            // 
            // label3
            // 
            this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(89, 105);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(66, 13);
            this.label3.TabIndex = 16;
            this.label3.Text = "User Name :";
            // 
            // txtPath
            // 
            this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtPath.Location = new System.Drawing.Point(164, 77);
            this.txtPath.Name = "txtPath";
            this.txtPath.Size = new System.Drawing.Size(192, 20);
            this.txtPath.TabIndex = 10;
            this.txtPath.Tag = "FolderPath";
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(89, 80);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(67, 13);
            this.label2.TabIndex = 13;
            this.label2.Text = "Folder Path :";
            // 
            // txtPassword
            // 
            this.txtPassword.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtPassword.Location = new System.Drawing.Point(164, 128);
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.PasswordChar = '*';
            this.txtPassword.Size = new System.Drawing.Size(100, 20);
            this.txtPassword.TabIndex = 12;
            this.txtPassword.Tag = "Password";
            // 
            // txtHost
            // 
            this.txtHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.txtHost.Location = new System.Drawing.Point(164, 49);
            this.txtHost.Name = "txtHost";
            this.txtHost.Size = new System.Drawing.Size(122, 20);
            this.txtHost.TabIndex = 8;
            this.txtHost.Tag = "ServerIP";
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(89, 52);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(54, 13);
            this.label1.TabIndex = 9;
            this.label1.Text = "ServerIP :";
            // 
            // checkBox1
            // 
            this.checkBox1.Checked = true;
            this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
            this.checkBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.checkBox1.Location = new System.Drawing.Point(16, 8);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(168, 24);
            this.checkBox1.TabIndex = 8;
            this.checkBox1.Tag = "Allow all MIME types";
            this.checkBox1.Text = "Allow all MIME types";
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "Min";
            this.columnHeader2.Width = 50;
            // 
            // buttonSettingsOK
            // 
            this.buttonSettingsOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.buttonSettingsOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.buttonSettingsOK.Location = new System.Drawing.Point(290, 282);
            this.buttonSettingsOK.Name = "buttonSettingsOK";
            this.buttonSettingsOK.Size = new System.Drawing.Size(75, 23);
            this.buttonSettingsOK.TabIndex = 1;
            this.buttonSettingsOK.Text = "OK";
            this.buttonSettingsOK.Click += new System.EventHandler(this.buttonSettingsOK_Click);
            // 
            // buttonSettingsCancel
            // 
            this.buttonSettingsCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.buttonSettingsCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.buttonSettingsCancel.Location = new System.Drawing.Point(370, 282);
            this.buttonSettingsCancel.Name = "buttonSettingsCancel";
            this.buttonSettingsCancel.Size = new System.Drawing.Size(75, 23);
            this.buttonSettingsCancel.TabIndex = 1;
            this.buttonSettingsCancel.Text = "Cancel";
            // 
            // columnHeaderMatchText
            // 
            this.columnHeaderMatchText.Text = "Description";
            this.columnHeaderMatchText.Width = 300;
            // 
            // columnHeaderMatchName
            // 
            this.columnHeaderMatchName.Text = "Match";
            this.columnHeaderMatchName.Width = 90;
            // 
            // SettingsForm
            // 
            this.AcceptButton = this.buttonSettingsOK;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.buttonSettingsCancel;
            this.ClientSize = new System.Drawing.Size(466, 311);
            this.Controls.Add(this.buttonSettingsOK);
            this.Controls.Add(this.tabControlSettings);
            this.Controls.Add(this.buttonSettingsCancel);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "SettingsForm";
            this.ShowInTaskbar = false;
            this.Text = "Settings";
            this.Load += new System.EventHandler(this.SettingsForm_Load);
            this.tabControlSettings.ResumeLayout(false);
            this.tabPageOutput.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRequests)).EndInit();
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		private void SettingsForm_Load(object sender, System.EventArgs e)
		{
			Settings.GetValue(this);
         

			if(this.textBoxDownloadFolder.Text == "")
				this.textBoxDownloadFolder.Text = System.Environment.CurrentDirectory;

			if(SelectedIndex != -1)
				this.tabControlSettings.SelectedIndex = SelectedIndex;
		}

		private void buttonSettingsOK_Click(object sender, System.EventArgs e)
		{
			Settings.SetValue(this);
		}

		private void checkBoxSettingsUseWindowsDefaultCodePage_CheckedChanged(object sender, System.EventArgs e)
		{
			
		}

		private void buttonAddExt_Click(object sender, System.EventArgs e)
		{
			FileTypeForm form = new FileTypeForm();
			if(form.ShowDialog() == DialogResult.OK)
			{
				
			
			}
		}

	
		private void buttonDownloadFolderBrowse_Click(object sender, System.EventArgs e)
		{
			BrowseForFolderClass form = new BrowseForFolderClass();
			form.Title = "Select folder to save crawled files";
			if(form.ShowDialog() == DialogResult.OK)
				this.textBoxDownloadFolder.Text = form.DirectoryPath;
		}

        private void button2_Click(object sender, EventArgs e)
        {
            using (var client = new SftpClient(txtHost.Text, txtUsername.Text, txtPassword.Text))
            {
                client.Connect();
                IEnumerable<SftpFile> listfiles = client.ListDirectory(txtPath.Text, null);
                foreach (SftpFile item in listfiles)
                {
                    if (item.FullName != null)
                    {

                    }
                }
                client.Disconnect();
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            // save configuration to textfile  with crypt  : 
            Settings.SetValue(this);

        }

        private void button1_Click_1(object sender, EventArgs e)
        {

        }


	}
}
